if (build_spawn) exitwith {hint "!!! Already Building !!!"};

hint "Building Mission ... Please do not touch the GM interface";

private ["_code"];

_text=ctrlText 20301;
call compile ("_code="+_text+";");
_typename=typeName _code;
//hint format["%1",_code];
if (isnil "_code")  exitWith { hint "!!! Error in mission code setup !!!"; };
if ((_typename!="ARRAY") or ((count _code)<1)) exitWith { hint "!!! Error in mission code setup !!!"; };

//Counting number of spawn in the code
_numspawn=count _code;

//hint format["%1",_numspawn];

//Storing current interface setup
_currentsetup=call vts_storespawnsetup;


build_spawn=true;
publicvariable "build_spawn";

for "_xspawn" from 0 to (_numspawn-1) do
{
  _currentspawn=_code select _xspawn;
  //user1 sidechat format["%1",_currentspawn];
  _datetype=_currentspawn select 0;
  
  //Spawn 2D or 3D
  if (_datetype==0) then
  {

    [_currentspawn] call vts_restorespawnsetup;
    console_spawn = true;
    publicvariable "console_spawn";
    sleep 0.5;
    hintsilent "Building Mission ... Please do not touch the GM interface";
    //player commandChat "Building Mission ... Please do not touch the GM interface";
  };
  
  //Balance and weapons unlocks
  if (_datetype==1) then
  {
    //Balance for each side
    _teambalance=_currentspawn select 1;
    
    vts_shopbalance_WEST=_teambalance select 0;
    vts_shopbalance_EAST=_teambalance select 1;
    vts_shopbalance_GUER=_teambalance select 2;
    vts_shopbalance_CIV=_teambalance select 3;
    
    
    vts_shopunlocklist=_currentspawn select 2;
    
    publicvariable "vts_shopbalance_WEST";
    publicvariable "vts_shopbalance_EAST";
    publicvariable "vts_shopbalance_GUER";
    publicvariable "vts_shopbalance_CIV";
    publicvariable "vts_shopunlocklist";
  };
  
};

//Resynchronising the server with the GM interface
sleep 1.0;
[_currentsetup] call vts_restorespawnsetup;

//Build done
hint "Building Completed";

build_spawn=false;
publicvariable "build_spawn";
closeDialog 8002; 

